import { useState } from "react";

const useAutoCompleteEmail = () => {
  const [emailOptions, setEmailOptions] = useState<{ value: string }[]>([]);
  /** 邮箱自动填充配置 */
  const setAutoCompleteEmail = (searchText: string) => {
    const suffix = [
      "@gmail.com",
      "@qq.com",
      "@163.com",
      "@sina.com.cn",
      "@hotmail.com",
      "@yahoo.com",
      "@sohu.com",
      "@outlook.com",
      "@foxmail.com",
      "@tom.com",
      "@icloud.com",
      "@126.com",
      "@yeah.net",
      "@aol.com",
      "@live.com",
    ];
    return suffix.map(item => {
      return { value: `${searchText}${item}` };
    });
  };

  const onSearch = (searchText: string) => {
    setEmailOptions(!searchText ? [] : setAutoCompleteEmail(searchText));
  };
  const autoCompleteCfg = { options: emailOptions, onSearch };
  return autoCompleteCfg;
};

export default useAutoCompleteEmail;
